using UnityEngine;

public class CannonWheelBehavior : MonoBehaviour {
	
	public float horizontalSensibility = 0.1f;
	public float verticalSensibility   = 0.1f;
	
	public float minimumX = -360F;
	public float maximumX = 360F;

	protected float rotationX = 0F;
	
	protected Quaternion xQuaternion;
	
	public bool isLaunched = false;
	
	public float impulse = 1000F;
	// Use this for initialization
	void Start () 
	{
	}
	
	// Update is called once per frame
	public virtual void Update ()
	{
		if(isLaunched)
			return;
		
		rotationX += Input.GetAxis("Mouse X") * horizontalSensibility;
		
		rotationX = ClampAngle (rotationX, minimumX, maximumX);
		
		xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
		
		transform.localRotation = xQuaternion;	
	}
	
	protected static float ClampAngle (float angle, float min, float max)
	{
		if (angle < -360F)
			angle += 360F;
		if (angle > 360F)
			angle -= 360F;
		
		return Mathf.Clamp (angle, min, max);
	}
}
